<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Github登录</title>
  <link href="../../../static/images/me.jpg" th:href="@{/images/me.jpg}" rel="icon" type="image/x-ico">
  <link rel="stylesheet" href="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/semantic-ui/2.2.4/semantic.min.css">
  <link rel="stylesheet" href="../../../static/css/me.css" th:href="@{/css/me.css}">
</head>
<body>

<br>
<br>
<br>
 <div class="m-container-small m-padded-tb-massive" style="max-width: 30em !important;">
   <div class="ur container">
     <div class="ui middle aligned center aligned grid">
       <div class="column">
         <h2 class="ui teal image header">
           <div class="content">
             登录中，耐心等待3秒...........
           </div>
         </h2>
       </div>
     </div>
   </div>
 </div>


<script src="https://unpkg.zhimg.com/jquery@3.2/dist/jquery.min.js"></script>
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-30-M/semantic-ui/2.2.4/semantic.js"></script>
<script>
  //获取url中的授权码
  function getQueryParams() {
    // var reg=new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
    var r=window.location.href.split("?")[1].split("&")[0].split("=")[1];
    if (r!=null)
      return decodeURI(r);
    return null;
  }

  var code = getQueryParams();
  //拿着code去申请令牌
  $.ajax({
    type : "POST",
    data:{ "code": code,"state":localStorage.getItem("state")},
    url : sessionStorage.getItem("requestUrl")+"/blog-auth-server/social/github/accessToken",
    async: false,
    success : function (res) {
      //返回成功
      if (res.code==200){
        //将令牌放入localStorage缓存
        localStorage.setItem("social_token",res.data);
        window.open("","_self").close();
      }else{
        alert("授权失败，请重试！");
        window.open("","_self").close();
      }
    },
    error: function(result) {
      alert("授权异常，请重试！");
      window.open("","_self").close();
    }
  });


</script>

</body>
</html>